package com.example.ch14fragmentsbooksdynamic

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity(),Coordinator {

    lateinit var fragBookDescription: BookDescription
    lateinit var fragBookTitle: BookTitle

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        fragBookTitle = BookTitle()
        fragBookDescription = BookDescription()
        var fragTransient = supportFragmentManager.beginTransaction()
        fragTransient.add(R.id.fragtop,fragBookTitle)
        fragTransient.add(R.id.fragbottom,fragBookDescription)
        fragTransient.commit()

    }

    override fun onBookChanged(index: Int) {
            fragBookDescription.changeDescription(index)
    }
}


interface Coordinator {
    fun onBookChanged(index:Int)
}